package com.rainliang.project.user.basic.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.rainliang.project.user.basic.bean.LoginBean;
import com.rainliang.project.user.basic.bean.RegistBean;
import com.rainliang.project.user.basic.bean.UserInfo;
import com.rainliang.project.user.basic.service.UserService;
import com.rainliang.project.util.MD5Util;

@SuppressWarnings("deprecation")
public class UserLoginController extends SimpleFormController {

	protected final Log logger = LogFactory.getLog(this.getClass());

	public UserLoginController() {
		setCommandClass(LoginBean.class);
	}

	protected ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response, Object command, BindException errors) throws Exception {
		LoginBean loginBean = (LoginBean) command;
		UserInfo userInfo=userService.login(loginBean);
		if(userInfo!=null){
			//TODO 登录成功 用户信息入缓存
			return new ModelAndView(okView);
		}
		return new ModelAndView(failView);
	}
	
	private UserService userService;
	private String okView;
	private String failView;

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String getOkView() {
		return okView;
	}

	public void setOkView(String okView) {
		this.okView = okView;
	}

	public String getFailView() {
		return failView;
	}

	public void setFailView(String failView) {
		this.failView = failView;
	}
	
	
}